import 'dart:ui';

import 'package:fish_redux/fish_redux.dart';
import 'package:fish_redux_demo/global_store/state.dart';
import 'package:flutter/material.dart' hide Action;

import 'action.dart';

Reducer<GlobalState> buildReducer() {
  return asReducer(<Object, Reducer<GlobalState>>{
    GlobalAction.changeThemeColor: _onChangeThemeColor
  });
}

/// 定义颜色集合
List<Color> _colors = <Color>[
  Colors.green,
  Colors.red,
  Colors.black,
  Colors.blue
];

/// 实现: 改变主题颜色函数
GlobalState _onChangeThemeColor(GlobalState state, Action action) {
  // 获取下一种颜色
  final Color next =
      _colors[((_colors.indexOf(state.themeColor) + 1) % _colors.length)];

  // 这里只改变其中的主题颜色参数, 故先clone后返回
  return state.clone()..themeColor = next;
}
